package cn.life.business.literature.service.impl;

import cn.life.common.entity.model.CMessage;
import cn.life.business.literature.dao.LiteratureDao;
import cn.life.business.literature.entity.po.Literature;
import cn.life.business.literature.entity.vo.LiteratuerVo;
import cn.life.business.literature.service.LiteratureService;
import cn.life.common.entity.vo.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:    文献实现层
 * @author wangzhenyu
 * @Date 2018/7/11
 */
@Service
public class LiteratureServiceImpl implements LiteratureService {

    @Autowired
    private LiteratureDao literatureDao;


    @Override
    public CMessage addLiterature(Literature literature) {
        return literatureDao.addLiterature(literature) == 1 ? CMessage.success() : CMessage.fail("添加文献失败！");
    }

    @Override
    public CMessage deleteLiterature(long literatureId) {
        return literatureDao.deleteLiterature(literatureId) == 1 ? CMessage.success() : CMessage.fail("删除文献失败！");
    }

    @Override
    public CMessage updateLiterature(Literature literature) {
        return literatureDao.updateLiterature(literature) == 1 ?CMessage.success() :CMessage.fail("修改文献失败");
    }

    @Override
    public CMessage getAllLiteratureInfo(LiteratuerVo literatuerVo) {
        Pagination<LiteratuerVo> list=literatureDao.getAllLiteratureInfo(literatuerVo);
        return CMessage.successByData(list);
    }

    @Override
    public CMessage getLiterature(LiteratuerVo literatuerVo) {
        literatuerVo=literatureDao.getLiteratuer(literatuerVo);
        //增加查阅数量
        literatureDao.addLiteratuerNumber(literatuerVo);
        return CMessage.successByData(literatuerVo);
    }


}
